package com.mooc.fuxi.ui.news;

import com.mooc.fuxi.entity.BannerEntity;
import com.mooc.fuxi.entity.NewsEntity;
import com.mooc.fuxi.entity.TypeEntity;
import com.mooc.fuxi.mvvm.BaseModel;
import com.mooc.fuxi.network.ApiService;
import com.mooc.fuxi.network.HeadInterceptor;
import com.mooc.fuxi.network.NetRepo;

import io.reactivex.Observable;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

//新闻列表页->获取3接口->banner;type;list
public class NewsModel extends BaseModel {
    public Observable<BannerEntity> requestBanner(){
        OkHttpClient.Builder okBuilder = new OkHttpClient.Builder();
        okBuilder.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY));
        okBuilder.addInterceptor(new HeadInterceptor());
        Retrofit.Builder builder = new Retrofit.Builder();
        builder.baseUrl("http://vueshop.glbuys.com/api/");
        builder.client(okBuilder.build());
        builder.addConverterFactory(GsonConverterFactory.create());
        builder.addCallAdapterFactory(RxJava2CallAdapterFactory.create());
        return builder.build().create(ApiService.class)
                .requestBanner();
    }

    public Observable<TypeEntity>requestType(){
        return NetRepo.getInstance().getRetrofit().create(ApiService.class)
                .requestType();
    }


    public Observable<NewsEntity>requestNews(int pagenum){
        return NetRepo.getInstance().getRetrofit().create(ApiService.class)
                .requestNews(1,pagenum,10);
    }

}
